import request from "@/api/request"

import { userApis } from "./apis"
import type {
  CommonRes,
  PhoneCodeLoginParam, UserInfo,
  UserPassLoginParam,
  UserPassLoginRes
} from './types'



export const userApi = {
    login(loginParam: UserPassLoginParam | PhoneCodeLoginParam): Promise<CommonRes<UserPassLoginRes>> { // 登录接口，用于获取用户信息和token
        return request({
            url: userApis.Login,
            method: 'post',
            data: loginParam,
        })
    },
    getInfo(): Promise<CommonRes<UserInfo>> {
        /**
         * 获取用户信息，用于显示在菜单和路由中
         */
        return request({
            url: userApis.GetInfo,
            method: 'post',
            headers: { 'Content-Type': 'application/json' }
        })
    },
    logout() { // 退出登录，用于清除token和用户信息，跳转到登录页面
        return request({
            url: userApis.Logout,
            method: 'post',
            headers: { 'Content-Type': 'application/json' }
        })
    },
  ListUsersByPage(params: any) {
    return request({
      url: userApis.ListUsersByPage,
      method: 'post',
      data: params,
      headers: { 'Content-Type': 'application/json' }
    })
  },
  DeleteUser(params: any) {
      return request({
        url: userApis.DeleteUser,
        method: 'post',
        data: params,
        headers: { 'Content-Type': 'application/json' }
      })
  },
  UpdateUser(params: any) {
      return request({
        url: userApis.UpdateUser,
        method: 'post',
        data: params,
        headers: { 'Content-Type': 'application/json' }
      })
  },
  GetUser(params: any) {
      return request({
        url: userApis.GetUser,
        method: 'post',
        data: params,
      })
  },
}
